package com.example.filter02.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(urlPatterns = "/demo1")
public class LoginCheckFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //只会执行一次，在tomcat启动时启动
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println(servletResponse.getContentType());
        System.out.println("方法执行之前");

        //放行执行
        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("方法结束");
    }

    @Override
    public void destroy() {
        //只会执行一次，在tomcat关闭时启动
    }
}
